import { reactive ,ref} from 'vue';

export function usePagination(getData: () => Promise<any>, initialPage = 10) {
    const totals = ref(0)
  const pageInfo = reactive({
    page: 1,
    pageSize: initialPage,
  });

  const handleSizechange = (size: number) => {
    pageInfo.pageSize = size;
    getData();
  };
  const handlePageNochange = (pageNo: number) => {
    pageInfo.page = pageNo;
    getData();
  };

  const resetPagination = () => {
    pageInfo.page = 1;
    pageInfo.pageSize = initialPage;
  };

  const setTotals = (all:number)=>{
    totals.value =all
  }

  return {
    totals,pageInfo,handleSizechange,handlePageNochange,resetPagination,setTotals
  }
}
